<?php include "templates/include/header.php" ?>

      <div id="adminHeader">
        <h2>Administration des Evenements</h2>
        <p>Vous etes connect&eacute; en tant que <b><?php echo htmlspecialchars( $_SESSION['username']) ?></b>. <a href="admin.php?action=logout"?>Se D&eacute;connecter</a></p>
      </div>

      <h1><?php echo htmlspecialchars( $results['pageTitle'] )?></h1>

      <form action="admin.php?action=<?php echo $results['formAction']?>" method="post">
        <input type="hidden" name="eventId" value="<?php echo $results['edit']->id ?>"/>

<?php if ( isset( $results['errorMessage'] ) ) { ?>
        <div class="errorMessage"><?php echo $results['errorMessage'] ?></div>
<?php } ?>

<?php 
  $data = Season::getList();
?>
        <table width="70%" align="center">
          <tr>
            <td>
              <label for="title">Evenement:</label>
              <input id="title" name="title" placeholder="Titre" maxlength="255" value="<?php if ( isset( $results['edit']->title ) ) echo htmlspecialchars( $results['edit']->title )?>"/>
            </td>
            <td>
              <label for="season_id">Saison:</label>
              <select id="season_id" name="season_id">
                <?php
                  foreach( $data['results'] as $season ) {
                    echo( '<option value="' . $season->id . '"');
                    if( isset( $results['edit']->id ) ) {
                      if( $results['edit']->season_id == $season->id ) {
                        echo( ' selected="yes"' );
                      }
                    }
                    echo(' >' . $season->title . '</option>' . "\n");
                  }
                ?>
              </select>
            </td>
          </tr>
        </table>
        
        <table align="center" width="90%">
          <?php
            if ( isset( $results['result']['results'] ) ) {
              foreach( $results['result']['results'] as $result ) { ?>
                <tr onclick="location='admin.php?action=editResult&amp;resultId=<?php echo( $result->id );?>'">
                  <td width="40%">
                    <?php
                      if ( isset( $result->home_team ) ) {
                        echo( htmlspecialchars( $result->home_team ) );
                      }
                    ?>
                  </td>
                  <td width="10%">
                    <?php
                      if ( isset( $result->home_score ) ) {
                        echo( htmlspecialchars( $result->home_score ) );
                      }
                    ?>
                  </td>
                  <td width="10%">
                    <?php
                      if ( isset( $result->away_score ) ) {
                        echo( htmlspecialchars( $result->away_score ) );
                      }
                    ?>
                  </td>
                  <td width="40%">
                    <?php
                      if ( isset( $result->away_team ) ) {
                        echo( htmlspecialchars( $result->away_team ) );
                      }
                    ?>
                  </td>
                </tr>
        <?php }
            }?>
        </table>
      
        <div class="buttons">
          <input type="submit" name="saveChanges" value="Enregister" />
          <input type="submit" formnovalidate name="cancel" value="Annuler" />
        </div>
      </form>

<?php if ( $results['edit']->id ) { ?>
      <p><a href="admin.php?action=newResult">Ajouter un R&eacute;sultat</a></p>
      <p><a href="admin.php?action=deleteEvent&amp;eventId=<?php echo $results['edit']->id ?>" onclick="return confirm('Supprimer cet element ?')">Supprimer cet Element</a></p>
<?php } ?>

<?php include "templates/include/footer.php" ?>
